function loadAttributes(json, property, node) {
    //json[property] = {};

    for (var i = 0; i < node.attributes.length; i++) {
        json[node.attributes[i].name] = node.attributes[i].value;
    }
}

function isEmpty(value) {
    return value == null || (typeof value == 'undefined');
}

function xml2json(elementRoot) {
    var json = {};

    if (elementRoot.attributes.length > 0) {
        var propertyName = elementRoot.nodeName;
       
        if (propertyName.indexOf(':') != -1) {
            var tokens = propertyName.split(':');
            propertyName = tokens[tokens.length - 1];
        }
       
        loadAttributes(json, propertyName, elementRoot);
    }

    if (elementRoot.childNodes.length > 0) {
        for (var i = 0; i < elementRoot.childNodes.length; i++) {
            var propertyName = elementRoot.childNodes[i].nodeName;
           
            if (propertyName.charAt(0) == '#') {
                if (!isEmpty(elementRoot.childNodes[i].nodeValue) && elementRoot.childNodes[i].nodeValue != '') {
                    json['nodeValue'] = elementRoot.childNodes[i].nodeValue;
                }
            } else {
                if (propertyName.indexOf(':') != -1) {
                    var tokens = propertyName.split(':');
                    propertyName = tokens[tokens.length - 1];
                }
               
                var property = xml2json(elementRoot.childNodes[i]);
               
                if (isEmpty(json[propertyName])) {
                    json[propertyName] = property;
                } else {
                    if ((isEmpty(json[propertyName].length))) {
                        var array = new Array();
                        array[0] = json[propertyName];
                       
                        json[propertyName] = array;
                    }   
                   
                    json[propertyName].push(property);       
                }
            }
        }
    }

    return json;
}